//
//  RouteNameMessageCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/4/5.
//

#import "RouteNameMessageCell.h"

@interface RouteNameMessageCell ()

@property (weak, nonatomic) IBOutlet UITextField *nameFiled;
@property (weak, nonatomic) IBOutlet UILabel *odometerLbl;
@property (weak, nonatomic) IBOutlet UILabel *durationLbl;
@property (weak, nonatomic) IBOutlet UILabel *climbingLbl;
@property (weak, nonatomic) IBOutlet UILabel *caloriesLbl;

@end

@implementation RouteNameMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (IBAction)clearButtonAction:(id)sender {
    _nameFiled.text = @"";
    if(_nameChangedBlock) {
        _nameChangedBlock(@"");
    }
}

- (IBAction)nameFieldEndAction:(id)sender {
    [_nameFiled resignFirstResponder];
}

- (IBAction)nameFieldValueChanged:(id)sender
{
    if(_nameChangedBlock) {
        _nameChangedBlock(_nameFiled.text);
    }
}

- (void)setName:(NSString *)name
{
    _nameFiled.text = name;
}

- (void)setEditModel:(CyclingRouteEditModel *)editModel
{
    self.name = editModel.name;
    
    self.odometerLbl.text = [NSString stringWithFormat:@"%.1f km", editModel.detailModel.actualdistance.doubleValue / 1000];
    self.durationLbl.text = editModel.detailModel.timelength;
    self.climbingLbl.text = editModel.detailModel.num;
    self.caloriesLbl.text = editModel.detailModel.calories;
}

@end
